[CmdletBinding()]
param(
    [string]$NameOfTheExecution,
    [switch]$ShowInfo,
    [switch]$CreateFile,
    [switch]$WriteDataFile,
    [switch]$ReadDataFile,
    [switch]$WriteLogFile,
    
    [switch]$ExtendedChecks,
    [switch]$StandardChecks, 

    [string[]]$Filename,
     
    [int]$CreateFile_SizeInMB=65536,
    [int]$TestLengthInSeconds=30,
    [string]$ResultFolder=".\",
    
    [switch]$PopulateDB,
    [string]$PopulateDB_DatabaseServerInstance,
    [string]$PopulateDB_DatabaseName,
    [int[]]$DataFile_BlockSizesSequential,
    [int[]]$DataFile_BlockSizesRandom,
    [int[]]$DataFile_OutstandingIOs,
    [int[]]$DataFile_Threads,
    [int[]]$LogFile_BlockSizes,
    [int[]]$LogFile_OutstandingIOs
    )

<# 
Block Sizes in KiloBytes to be tested.
#>


IF($StandardChecks -eq $True) {
    IF($DataFile_BlockSizesSequential.Count -eq 0) { $DataFile_BlockSizesSequential = @(8,32,64,128,256) }
    IF($DataFile_BlockSizesRandom.Count -eq 0) { $DataFile_BlockSizesRandom = @(8,32,64,128,256) }
    IF($DataFile_OutstandingIOs.Count -eq 0) { $DataFile_OutstandingIOs = @(0,8,32) }
    IF($DataFile_Threads.Count -eq 0) { $DataFile_Threads =@(1,8) }
    IF($LogFile_BlockSizes.Count -eq 0) { $LogFile_BlockSizes = @(1,8,16,64) }
    IF($LogFile_OutstandingIOs.Count -eq 0) { $LogFile_OutstandingIOs = @(0,8,32) }

}

IF($ExtendedChecks -eq $True) {
<# 
Notice that Extended tests take much longer to run. When I prepare SQL Server for production 
this is part of my acceptance kit but it takes very long to run.
#>
$DataFile_BlockSizesSequential = @(8,16,32,64,128,256,512)
$DataFile_BlockSizesRandom = @(8,16,32,64)
$DataFile_OutstandingIOs = @(0,8,32)
$DataFile_Threads =@(1,2,4,8)

$LogFile_BlockSizes = @(1,2,4,8,16,32,64)
$LogFile_OutstandingIOs = @(0,8,32)

}

$currentDate = Get-Date -format yyyy-MM-dd-HH-mm-ss
$currentDateSQL = Get-Date -format 'yyyy-MM-dd HH:mm:ss'

IF($CreateFile -eq $True) {
    IF(-not($Filename)) { 
        $Filename = Read-Host 'Filename' 
    }

    foreach($fname in $Filename) {
        "$fname 2 0x0 $CreateFile_SizeInMB" | Out-File -Encoding ascii .\qumioparams
        Invoke-Expression  ".\SQLIO.exe -fsequential -Fqumioparams"
        rm qumioparams
    }
}
$CurrentPath = Split-Path $MyInvocation.MyCommand.Path

IF($WriteLogFile -eq $True) {
    IF(-not($Filename)) { 
        $Filename = Read-Host 'Filename' 
    }
    foreach($bSize in $LogFile_BlockSizes) {
        foreach($outstanding in $LogFile_OutstandingIOs) {

            $ResultFolder + "\Log-Write-" + $bSize + "kB-" + $outstanding +"out-" + $Filename[0].Replace(":","").Replace("\","-") + "-" + $currentDate + ".log"
                
            foreach($fname in $Filename) {
                
                
                    
                $queryToRun = {param($CurrentPath,$InvocationName,$ResultFolder,$bSize,$outstanding,$Filename,$currentDate,$currentDateSQL,$TestLengthInSeconds,$NameOfTheExecution)
                    Set-Location $CurrentPath
                    
                    $currentFileName = $ResultFolder + "\Log-Write-" + $bSize + "kB-" + $outstanding +"out-" + $Filename.Replace(":","").Replace("\","-") + "-" + $currentDate + ".log"
                    Write-Host $currentFileName
                    $InvocationName + ": WriteLogFile $env:computername.$env:userdnsdomain $currentDateSQL $TestLengthInSeconds $bSize $outstanding '$Filename'" | Out-File -Encoding ascii $currentFileName
                    $NameOfTheExecution  | Out-File -Append -Encoding ascii $currentFileName
                    Invoke-Expression ".\SQLIO.exe -kW -s$TestLengthInSeconds -fsequential -t1 -o$outstanding -b$bSize -LSi -BH '$Filename'" | Out-File -Append -Encoding ascii $currentFileName
                } 
                Start-Job $queryToRun -ArgumentList $CurrentPath,$MyInvocation.MyCommand.Name,$ResultFolder,$bSize,$outstanding,$fname,$currentDate,$currentDateSQL,$TestLengthInSeconds,$NameOfTheExecution 
            }
            Get-Job | Wait-Job
            Get-Job | Remove-Job
        }
    }
}

IF($WriteDataFile -eq $True) {
    IF(-not($Filename)) { 
        $Filename = Read-Host 'Filename' 
    }
    foreach($outstanding in $DataFile_OutstandingIOs) {
        foreach($threads in $DataFile_Threads) {
            foreach($bSize in $DataFile_BlockSizesSequential) {
                foreach($fname in $Filename) {
                    $queryToRun = {param($CurrentPath,$InvocationName,$ResultFolder,$bSize,$threads,$outstanding,$Filename,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL)
                        Set-Location $CurrentPath
                        $currentFileName = $ResultFolder + "\\Data-Write-Seq-" + $bSize + "kB-" + $threads +"t-"+ $outstanding +"out-" + $Filename.Replace(":","").Replace("\","-") + "-" + $currentDate + ".log"
                        $currentFileName
                        $InvocationName + ": WriteDataFile $env:computername.$env:userdnsdomain $currentDateSQL Sequential $TestLengthInSeconds $bSize $threads $outstanding '$Filename'" | Out-File -Encoding ascii $currentFileName
                        $NameOfTheExecution  | Out-File -Append -Encoding ascii $currentFileName
                        Invoke-Expression ".\SQLIO.exe -kW -s$TestLengthInSeconds -fsequential -t$threads -o$outstanding -b$bSize -LSi -BH '$Filename'" | Out-File -Append -Encoding ascii $currentFileName
                    }
                    Start-Job $queryToRun -ArgumentList $CurrentPath,$MyInvocation.MyCommand.Name,$ResultFolder,$bSize,$threads,$outstanding,$fname,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL
                }
                Get-Job | Wait-Job
                Get-Job | Remove-Job
            }
            foreach($bSize in $DataFile_BlockSizesRandom) {
                foreach($fname in $Filename) {
                    $queryToRun = {param($CurrentPath,$InvocationName,$ResultFolder,$bSize,$threads,$outstanding,$Filename,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL)
                        Set-Location $CurrentPath
                        $currentFileName = $ResultFolder + "\\Data-Write-Rand-" + $bSize + "kB-" + $threads +"t-"+ $outstanding +"out-" + $Filename.Replace(":","").Replace("\","-") + "-" + $currentDate + ".log"
                        $currentFileName
                        $InvocationName + ": WriteDataFile $env:computername.$env:userdnsdomain $currentDateSQL Random $TestLengthInSeconds $bSize $threads $outstanding '$Filename'" | Out-File -Encoding ascii $currentFileName
                        $NameOfTheExecution  | Out-File -Append -Encoding ascii $currentFileName
                        Invoke-Expression ".\SQLIO.exe -kW -s$TestLengthInSeconds -frandom -t$threads -o$outstanding -b$bSize -LSi -BH '$Filename'" | Out-File -Append -Encoding ascii $currentFileName
                    }
                    Start-Job $queryToRun -ArgumentList $CurrentPath,$MyInvocation.MyCommand.Name,$ResultFolder,$bSize,$threads,$outstanding,$fname,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL
                }
                Get-Job | Wait-Job
                Get-Job | Remove-Job
            }
        }
    }
}


IF($ReadDataFile -eq $True) {
    IF(-not($Filename)) { 
        $Filename = Read-Host 'Filename' 
    }
    foreach($outstanding in $DataFile_OutstandingIOs) {
        foreach($threads in $DataFile_Threads) {
            foreach($bSize in $DataFile_BlockSizesSequential) {
                foreach($fname in $Filename) {
                    $queryToRun = {param($CurrentPath,$InvocationName,$ResultFolder,$bSize,$threads,$outstanding,$Filename,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL)
                        Set-Location $CurrentPath
                        $currentFileName = $ResultFolder + "\\Data-Read-Seq-" + $bSize + "kB-" + $threads +"t-"+ $outstanding +"out-" + $Filename.Replace(":","").Replace("\","-") + "-" + $currentDate + ".log"
                        $currentFileName
                        $InvocationName + ": ReadDataFile $env:computername.$env:userdnsdomain $currentDateSQL Sequential $TestLengthInSeconds $bSize $threads $outstanding '$Filename'" | Out-File -Encoding ascii $currentFileName
                        $NameOfTheExecution  | Out-File -Append -Encoding ascii $currentFileName
                        Invoke-Expression ".\SQLIO.exe -kR -s$TestLengthInSeconds -fsequential -t$threads -o$outstanding -b$bSize -LSi -BH '$Filename'" | Out-File -Append -Encoding ascii $currentFileName
                    }
                    Start-Job $queryToRun -ArgumentList $CurrentPath,$MyInvocation.MyCommand.Name,$ResultFolder,$bSize,$threads,$outstanding,$fname,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL
                }
                Get-Job | Wait-Job
                Get-Job | Remove-Job
            }
            foreach($bSize in $DataFile_BlockSizesRandom) {
                foreach($fname in $Filename) {
                    $queryToRun = {param($CurrentPath,$InvocationName,$ResultFolder,$bSize,$threads,$outstanding,$Filename,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL)
                        Set-Location $CurrentPath
                        $currentFileName = $ResultFolder + "\\Data-Read-Rand-" + $bSize + "kB-" + $threads +"t-"+ $outstanding +"out-" + $Filename.Replace(":","").Replace("\","-") + "-" + $currentDate + ".log"
                        $currentFileName
                        $InvocationName + ": ReadDataFile $env:computername.$env:userdnsdomain $currentDateSQL Random $TestLengthInSeconds $bSize $threads $outstanding '$Filename'" | Out-File -Encoding ascii $currentFileName
                        $NameOfTheExecution  | Out-File -Append -Encoding ascii $currentFileName
                        Invoke-Expression ".\SQLIO.exe -kR -s$TestLengthInSeconds -frandom -t$threads -o$outstanding -b$bSize -LSi -BH '$Filename'" | Out-File -Append -Encoding ascii $currentFileName
                    }
                    Start-Job $queryToRun -ArgumentList $CurrentPath,$MyInvocation.MyCommand.Name,$ResultFolder,$bSize,$threads,$outstanding,$fname,$currentDate,$TestLengthInSeconds,$NameOfTheExecution,$currentDateSQL
                }
                Get-Job | Wait-Job
                Get-Job | Remove-Job
            }
        }
    }
}

IF($PopulateDB -eq $True) {

    IF(-not($PopulateDB_DatabaseServerInstance)) { 
        $PopulateDB_DatabaseServerInstance = Read-Host 'DatabaseServer' 
    }
    IF(-not($PopulateDB_DatabaseName)) { 
        $PopulateDB_DatabaseName = Read-Host 'DatabaseName' 
    }
    
    "Creating needed tables and views"
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'SqlioResult')) BEGIN CREATE TABLE [dbo].[SqlioResult] ([SqlioResultID] int not null identity primary key clustered,[ComputerName] varchar(300) not null,[Datetime] datetime2 not null,[ExecutionName] varchar(200), [Operation] char(20) not null,[AccessType] char(10) not null,[TestTimeSeconds] smallint not null,[BlockSizeKB] smallint not null,[Threads] tinyint not null,[OutstandingRequests] tinyint not null,[Filename] varchar(255),[FileSizeMB] int,[IOPerSecond] decimal(10,2),[MBPerSecond] decimal(10,2),[MinInitLatency_us] int,[AvgInitLatency_us] int,[MaxInitLatency_us] int,[MinLatency_ms] int,[AvgLatency_ms] int,[MaxLatency_ms] int) END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'SqlioHistogram')) BEGIN CREATE TABLE [dbo].[SqlioHistogram] ([SqlioHistogramID] int not null identity primary key clustered,[ComputerName] varchar(300) not null,[Datetime] datetime2 not null,[ExecutionName] varchar(200),[Operation] char(20) not null,[AccessType] char(10) not null,[TestTimeSeconds] smallint not null,[BlockSizeKB] smallint not null,[Threads] tinyint not null,[OutstandingRequests] tinyint not null,[Filename] varchar(255),[FileSizeMB] int,[ResponseTime_ms] tinyint not null,[ResponseTimeDensity_percent] tinyint not null) END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimAccessType')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimAccessType] AS select DISTINCT [AccessType] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimBlockSizeKB')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimBlockSizeKB] AS select DISTINCT [BlockSizeKB] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimComputerName')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimComputerName] AS select DISTINCT [ComputerName] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimDatetime')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimDatetime] AS select DISTINCT [Datetime] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimFilename')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimFilename] AS select DISTINCT [Filename] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimFileSizeMB')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimFileSizeMB] AS select DISTINCT [FileSizeMB] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimOperation')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimOperation] AS select DISTINCT [Operation] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimOutstandingRequests')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimOutstandingRequests] AS select DISTINCT [OutstandingRequests] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimTestTimeSeconds')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimTestTimeSeconds] AS select DISTINCT [TestTimeSeconds] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimThreads')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimThreads] AS select DISTINCT [Threads] from [dbo].[SqlioResult]' END`""
    Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'dbo' AND  TABLE_NAME = 'DimExecutionName')) BEGIN execute sp_executesql N'CREATE VIEW [dbo].[DimExecutionName] AS select DISTINCT [ExecutionName] from [dbo].[SqlioResult]' END`""


  
    "Populating database: $PopulateDB_DatabaseName at server: $PopulateDB_DatabaseServerInstance from: $ResultFolder"

    $SQLCmd =""

   # $fileEntries = [IO.Directory]::GetFiles($ResultFolder); 
   # foreach($fileName in $fileEntries) 
   [string]$fname=""
   foreach($fname in Get-ChildItem $ResultFolder)
    { 
        Write-Host -NoNewline "Processing $fname"
        IF(($fname.StartsWith("Data-Write-Rand-") -or $fname.StartsWith("Data-Write-Seq-") -or $fname.StartsWith("Data-Read-Seq-") -or $fname.StartsWith("Data-Read-Rand-")) -and $fname.EndsWith(".log")) {
            
            $filePath = $ResultFolder + "\" + $fname;
            $fileContent = (Get-Content -path $filePath).Split([environment]::NewLine)
            $i_line = 0;

            $file_operation=""
            $file_computerName=""
            $file_date=""
            $file_time=""
            $file_accessType=""
            $file_secs=0
            $file_bSize=0
            $file_threads=0
            $file_outstanding=0
            $file_datafile=""
            $file_size=0
            $file_io=0
            $file_MBperSecond=0
            $file_Min_Init_Latency=0
            $file_Avg_Init_Latency=0
            $file_Max_Init_Latency=0
            $file_Min_Latency=0
            $file_Avg_Latency=0
            $file_Max_Latency=0
            $file_histogram=""

            foreach($line in $fileContent) {
                IF($i_line -eq 0) {
                    $fileParams = $line.Split(" ");
                    $file_operation = $fileParams[1]
                    $file_computerName = $fileParams[2]
                    $file_date = $fileParams[3]
                    $file_time = $fileParams[4]
                    $file_accessType = $fileParams[5]
                    $file_secs = $fileParams[6]
                    $file_bSize = $fileParams[7]
                    $file_threads = $fileParams[8]
                    $file_outstanding = $fileParams[9]
                    $file_datafile = ($line.Split("'"))[1]
                }
                ELSEIF($i_line -eq 1) {
                    $file_executionName = $line
                }
                ELSE {
                    IF($line.StartsWith("using current size")) {
                        $file_size = ($line.Replace("using current size: ","").Split(" "))[0]
                    }
                    ELSEIF($line.StartsWith("IOs/sec:")) {
                        $file_io = $line.Replace("IOs/sec:","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("MBs/sec:")) {
                        $file_MBperSecond = $line.Replace("MBs/sec:","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("Min_Init_Latency(us):")) {
                        $file_Min_Init_Latency = $line.Replace("Min_Init_Latency(us):","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("Avg_Init_Latency(us):")) {
                        $file_Avg_Init_Latency = $line.Replace("Avg_Init_Latency(us):","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("Max_Init_Latency(us):")) {
                        $file_Max_Init_Latency = $line.Replace("Max_Init_Latency(us):","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("Min_Latency(ms):")) {
                        $file_Min_Latency = $line.Replace("Min_Latency(ms):","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("Avg_Latency(ms):")) {
                        $file_Avg_Latency = $line.Replace("Avg_Latency(ms):","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("Max_Latency(ms):")) {
                        $file_Max_Latency = $line.Replace("Max_Latency(ms):","").Replace(" ","")
                    }
                    ELSEIF($line.StartsWith("%:")) {
                        $file_histogram = $line.Replace("%:","").Replace("  "," ").Split(" ")
                    }
                }


                $i_line++
            }

            $output = Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"INSERT INTO [dbo].[SqlioResult] ([ComputerName],[Datetime],[ExecutionName],[Operation],[AccessType],[TestTimeSeconds],[BlockSizeKB],[Threads],[OutstandingRequests],[Filename],[FileSizeMB],[IOPerSecond],[MBPerSecond],[MinInitLatency_us],[AvgInitLatency_us],[MaxInitLatency_us],[MinLatency_ms],[AvgLatency_ms],[MaxLatency_ms]) VALUES ('$file_computerName','$file_date $file_time','$file_executionName','$file_operation','$file_accessType','$file_secs','$file_bSize','$file_threads','$file_outstanding','$file_datafile','$file_size','$file_io','$file_MBperSecond','$file_Min_Init_Latency','$file_Avg_Init_Latency','$file_Max_Init_Latency','$file_Min_Latency','$file_Avg_Latency','$file_Max_Latency') `""
            
            $ResponseTime_ms=0
            foreach($ResponseTimeDensity_percent in $file_histogram) {
                $output = Invoke-Expression "SQLCMD -S $PopulateDB_DatabaseServerInstance -d $PopulateDB_DatabaseName -Q `"INSERT INTO [dbo].[SqlioHistogram] ([ComputerName],[Datetime],[ExecutionName],[Operation],[AccessType],[TestTimeSeconds],[BlockSizeKB],[Threads],[OutstandingRequests],[Filename],[FileSizeMB],[ResponseTime_ms],[ResponseTimeDensity_percent]) VALUES ('$file_computerName','$file_date $file_time','$file_executionName','$file_operation','$file_accessType','$file_secs','$file_bSize','$file_threads','$file_outstanding','$file_datafile','$file_size','$ResponseTime_ms','$ResponseTimeDensity_percent')`""
                
                $ResponseTime_ms++
            }

        }
        Write-Host "...File removed...Done!"
        Remove-Item $filePath

    } 
    
}